package com.example.algorithm.no0070.solution;

import com.example.algorithm.no0070.Solution;

/**
 * @Description 解答实现-爬楼梯-动态规划
 * @ClassName SolutionImpl
 * @Author Administrator
 * @Date 2020/5/16 12:48
 * @Version 1.0.0
 */
public class SolutionImpl1 implements Solution {
    @Override
    public int climbStairs(int n) {
        if( n == 1) {
            return 1;
        }
        else if( n == 2) {
            return 2;
        } else {
            int[] a = new int[n];
            a[0] = 1;
            a[1] = 2;
            for(int i = 2; i < n; i++) {
                a[i] = a[i-1] + a[i-2]; // 动态规划表达式
            }
            return a[n-1];
        }

//        if (n == 1) {
//            return 1;
//        }
//        int[] dp = new int[n + 1];
//        dp[1] = 1;
//        dp[2] = 2;
//        for (int i = 3; i <= n; i++) {
//            dp[i] = dp[i - 1] + dp[i - 2];
//        }
//        return dp[n];
    }
}
